<template>
  <div class="header-container">
    <div class="l-content">
      <!-- 左侧折叠按钮 -->
      <el-button
        style="margin-right: 20px"
        @click="handelMenu"
        icon="el-icon-menu"
        size="mini"
      ></el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item
          v-for="item in tags"
          :key="item.path"
          @click.native="handleBreadcrumbClick(item.path)"
          :class="{ 'active-breadcrumb': activeBreadcrumb === item.path }"
        >
          {{ item.label }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img class="user" src="../assets/images/user.png" alt="" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人中心</el-dropdown-item>
          <div @click="logout">
            <el-dropdown-item>退出登录</el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      activeBreadcrumb: this.$route.path
    }
  },
  methods: {
    handelMenu () {
      this.$store.commit('collapseMenu')
    },
    /**
     * 处理面包屑点击事件
     * 当点击的面包屑路径与当前路由路径不一致时，导航到点击的路径
     * @param {string} path - 点击的面包屑对应的路径
     */
    handleBreadcrumbClick (path) {
      // 检查当前路由路径是否与点击的面包屑路径相同
      if (this.$route.path !== path) {
        // 导航到点击的路径
        this.$router.push(path)
        this.activeBreadcrumb = path
      }
    },
    logout () {
      //跳转到登录页面
      console.log('退出登录')

      this.$router.push('/login')
    }
  },
  computed: {
    ...mapState({
      tags: state => state.tab.tabList
    })
  }
}
</script>
<style lang="less" scoped>
.header-container {
  padding: 0 20px;
  background-color: #333;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .text {
    color: #fff;
    font-size: 14px;
    margin-left: 10px;
  }
  .r-content {
    .user {
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
  .l-content {
    display: flex;
    align-items: center;
    /deep/.el-breadcrumb__item {
      .el-breadcrumb__inner {
        font-weight: normal;
        cursor: pointer; // 添加鼠标手样式
        &.is-link {
          color: #666;
        }
      }
      &:last-child {
        .el-breadcrumb__inner {
          color: #666;
        }
      }
      &.active-breadcrumb {
        .el-breadcrumb__inner {
          color: #fff; // 或者其他你想要的被点击状态的颜色
          font-weight: bold; // 或者其他你想要的被点击状态的样式
        }
      }
    }
  }
}
</style>
